package com.weipai.demo.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Properties;

/**
 * 读取properties下文件属性
 *
 * @author songmengqiang
 * @create 2018-08-30 14:08
 **/
public class PropUtils {
    private static final Logger logger = LoggerFactory.getLogger(PropUtils.class);
    private static final Properties properties = new Properties();
    private static final String path = "properties/vendor.properties,properties/system.properties";

    static {
        try {
            String[] paths = path.split(",");
            if (paths != null) {
                for (String pth : paths) {
                    properties.load(PropUtils.class.getClassLoader().getResourceAsStream(pth));
                }
            }
//            properties.load(PropUtils.class.getClassLoader().getResourceAsStream(path));
            logger.info("proputis load success");
        } catch (IOException e) {
            logger.error("proputils load with error {}", e);
        }
    }

    public static String getString(String key) {
        return properties.getProperty(key);
    }

    public static Integer getInteger(String key) {
        return Integer.valueOf(properties.getProperty(key));
    }
}
